        $(function () {
				$.ajaxSetup({
					cache: false,
					headers: {
						"header":localStorage.getItem("token")
					}
				});
            $("#tt").datagrid({
            	idField : 'id',
            	title: "",
                url : basePath + "expenses/page",
                width: "100%",  
                height: "550px",
                singleSelect : false, /* 是否选中一行 */
                pagination : true,/* 是否显示下面的分页菜单 */
                border:true,
				onClickRow: function(index,row){
                	$("#tt").datagrid("clearSelections");
				},
                rowStyler: function() {
                	　　return 'height: 60px';
                	},  
                rownumbers:true,
                columns : [ [  {field : 'id', checkbox: false,hidden:true},
								{field : 'payTime',title : '消费时间',width : '15%',align : 'center'},
								{field : 'payMoney',title : '消费金额(元)',width : '9%',align : 'center'},
								{field : 'content',title : '消费内容',width : '20%',align : 'center'},
								{field : 'type',title : '类型',width : '15%',align : 'center'},
								{field : 'fullAddress',title : '消费地点',width : '30%',align : 'center'},
								
								{field : 'op',title : '操作',width : '100',align : 'center',
								formatter:function(value,row,index){
									var id = row.id.toString();
									var del = '<a href="#" onclick="doDelete(\'' + id + '\')">删除</a>';
									//var del = "<a class='fonta' href='#' " + "onclick=doDelete(" + id +");>删除<a/>";

									var blank = "&nbsp;&nbsp;|";
									return del;
								}
					}

                ]],
            	loadMsg : '数据加载中,请稍候......'
            }); 
  
            var p = $('#tt').datagrid('getPager');  
            $(p).pagination({  
                /*
				 * 页数文本框前显示的汉字 修改每页默认条数 搜索pageList在jquery.easyui.min.js中修改，
				 * 分页区下拉分页数量集合和默认每页分页条数 striped属性 交替行换色
				 */  
                beforePageText: '第',  
                afterPageText: '页    共 {pages} 页',  
                displayMsg: '当前显示 {from}-{to} 条记录,共 {total} 条记录'  
            });

        }
        );
        // 搜索
        function doSearch() {
            $('#tt').datagrid('load', {  
            	payDate1: $('#payDate1').val(),
				payDate2: $('#payDate2').val(),
				content: $('#content').val()
			});
        }

		function doSearchExpenseByDate() {
			if ($("#payDate1").val() == "" || $("#payDate2").val() == "") {
				$.messager.alert('提示:','查询日期不能为空!','error');
			} else {
				$.ajax({
					type:"post",
					url:basePath + "expenses/searchExpenseByDate",
					beforeSend: function(request) {
						request.setRequestHeader("header", localStorage.getItem("token"));
					},
					data : $('#qryForm').serializeArray(),
					cache:false,
					dataType: "json",
					success:function(result) {
						$.messager.alert('SUCCESS',result.result,'SUCCESS');
					}
				});
			}
		}
        
        function clearQry() {
			//$("#measureTime1").datebox("setValue","");
			//$("#measureTime2").datebox("setValue","");

			$("#qryForm")[0].reset();
			$("[name='payDate1']").val("");
			$("[name='payDate2']").val("");
			$("[name='content']").val("");
			doSearch();
		}

        // 新增框修改框弹出
        function add(){
        	var title = "新增";
            $('#addExpensesDlg').css("top","0").dialog({
                title: title,
                width: 1000,
                height: 400,
                closed: false,
                cache: false,
                href: basePath + 'navigator?page=/expenses/add',
				onLoad:function(){
					initComboboxData();
				},
                modal: true
            });       	
        }

		function initComboboxData(){
			$('#type').combobox({
				//disabled:true,
				url:basePath + 'dict/loadCombobox/expenseType/0',
				valueField:'name',
				textField:'name',
				prompt: '请选择...',
				editable:false,
				onLoadSuccess:function(){ //默认选中第一条数据
					var data= $('#type').combobox("getData");
					$('#type').combobox('select', data[0].name);
				}
			});
			///////////////
			$('#countryId').combobox({
				//disabled:true,
				url:basePath + 'dict/loadCombobox/area/0',
				valueField:'id',
				textField:'name',
				prompt: '请选择...',
				editable:false,
				onLoadSuccess:function(){ //默认选中第一条数据
					// var data= $('#countryId').combobox("getData");
					// $('#countryId').combobox('select', data[0].id);
				},
				onChange:  function () {
					$("#country").val($('#countryId').combobox('getText'));
					$('#provinceId').combobox({
						//disabled:true,
						url:basePath + 'dict/loadCombobox/area/' + $('#countryId').combobox('getValue'),
						valueField:'id',
						textField:'name',
						prompt: '请选择...',
						editable:false,
						onLoadSuccess:function(){ //默认选中第一条数据
							//var data= $('#provinceId').combobox("getData");
							//$('#provinceId').combobox('select', data[0].id);
						},
						onChange:  function () {
							$("#province").val($('#provinceId').combobox('getText'));
							$('#cityId').combobox({
								//disabled:true,
								url:basePath + 'dict/loadCombobox/area/' + $('#provinceId').combobox('getValue'),
								valueField:'id',
								textField:'name',
								prompt: '请选择...',
								editable:false,
								onLoadSuccess:function(){ //默认选中第一条数据
									//var data= $('#cityId').combobox("getData");
									//$('#cityId').combobox('select', data[0].id);
								},
								onChange:  function () {
									//alert($('#countryId').combobox('getValue'))
									$("#city").val($('#cityId').combobox('getText'));
								}
							});
						}
					});
				}
			});
		}


        // 新增
        function submitAddExpenses(){
			var v = $("#addff").form("validate");//验证通过为true
			if(!v){
				$.messager.alert('错误提示',"请填写完整信息!",'warning');
				return;
			}

			//$("#submitAddExpensesId").css({'background-color' : 'gray'});
			//$("#submitAddExpensesId").attr("disabled", true);
			setBtnDisable("submitAddExpensesId");
			loadingProgress();
			$.ajax({
				type:"post",
				url:basePath+"expenses/add",
				beforeSend: function(request) {
					request.setRequestHeader("header", localStorage.getItem("token"));
				},
				data : $('#addff').serializeArray(),
				cache:false,
				dataType: "json",
				success:function(result) {
					closeProgress();
					$.messager.show({
						title:'提示',
						msg:result.result,
						timeout:5000,
						showType:'slide'
					});
					cancelDlg1();
					$('#tt').datagrid('reload');// 刷新
				}
			});
			//setBtnAvaible("submitAddExpensesId");
        } 


        // 删除
        function doDelete(id) {
        	$.messager.confirm('提示', '你确定要删除这条记录吗?',function(r){
        		if(r){
        			$.ajax({
                        type:"delete",
                        url:basePath + "expenses/delete/" + id,
                        cache:false,
                        dataType: "json", // this is important
                        success:function(result) {
                         	$.messager.show({
                         		title:'提示',
                         		msg:'删除成功',
                         		timeout:5000,
                         		showType:'slide'
                         	});
                        	$('#tt').datagrid('reload');// 刷新

                        }
                    });
        		}

        	})
           
        }
        // 关闭弹窗
        function cancelDlg1(){
        	$('#addExpensesDlg').dialog("close");
        }
        //关闭弹窗
        function cancelDlg(dlgName){
        	$('#'+dlgName).dialog("close");
        }




		



